home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume3 / runfilter < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  3.5 KB

  1. Path: xanth!mcnc!gatech!ukma!husc6!necntc!ncoast!allbery
  2. From: liz@grian.UUCP (Liz Allen-Mitchell)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i067: runfilter for Sun textedit
  5. Message-ID: <1395@grian.UUCP>
  6. Date: 29 Jun 88 17:28:31 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: liz@grian.UUCP (Liz Allen-Mitchell)
  9. Organization: College Park Software, Altadena, CA
  10. Lines: 87
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. Posting-number: Volume 3, Issue 67
  14. Submitted-by: "Liz Allen-Mitchell" <liz@grian.UUCP>
  15. Archive-name: runfilter
  16.  
  17. The following is a program you can use with Sun's textedit to filter
  18. text through arbitray commands -- something I wanted to do for a long
  19. time!  What you do is type the command on a line by itself above the
  20. region you want to filter through the command or where you want the
  21. output of the command to go.  Then select the region and hit the key
  22. you bound runfilter to.  For example, the shar below was created by
  23. putting the line:
  24.     (cd bin; shar runfilter)
  25. in this buffer, selecting it and hitting the R15 key.
  26.  
  27. It would be faster in C, but it isn't too slow...  The code I found I
  28. needed to use to get the command to run is arcane, but nothing else
  29. wanted to work.  Comments would be appreciated.
  30.  
  31. Enjoy!
  32.  
  33.                 - Liz
  34.  
  35. #! /bin/sh
  36. # This is a shell archive.  Remove anything before this line, then unpack
  37. # it by saving it into a file and typing "sh file".  To overwrite existing
  38. # files, type "sh file -c".  You can also feed this as standard input via
  39. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  40. # will see the following message at the end:
  41. #        "End of shell archive."
  42. # Contents:  runfilter
  43. # Wrapped by liz@grian on Wed Jun 29 10:24:03 1988
  44. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  45. if test -f 'runfilter' -a "${1}" != "-c" ; then 
  46.   echo shar: Will not clobber existing file \"'runfilter'\"
  47. else
  48. echo shar: Extracting \"'runfilter'\" \(1232 characters\)
  49. sed "s/^X//" >'runfilter' <<'END_OF_FILE'
  50. X#!/bin/csh -f
  51. X#
  52. X# This takes standard input, assumes the first line is a command and the
  53. X# rest is stuff to be filtered through the command.  It is for binding to
  54. X# a key in textedit.  For example, put the following in your .textswrc:
  55. X#    /*
  56. X#     * Take the first line of the pending delete region as a
  57. X#     * command and run the command with the rest of the region as
  58. X#     * input.  The output (including error output) replaces the
  59. X#     * region.  If you want to run a command with a ; in it, use
  60. X#     * ()'s around it.
  61. X#     */
  62. X#    KEY_RIGHT(15)   FILTER
  63. X#    runfilter
  64. X
  65. set prefix=/tmp/rf$$
  66. onintr cleanup
  67. X
  68. X# Split up the input into $prefix.00 and .01.  The 00 file will contain
  69. X#    the command and the 01 file will contain the text to be filtered.
  70. csplit -f $prefix. -s - 2
  71. X
  72. X# Execute the command redirecting both standard out and error out to
  73. X#    regular output so any errors show up in the editor.  Not using
  74. X#    eval since the quotes in something like:
  75. X#        sed 's/ /    /'
  76. X#    disappear too soon and the shell turns the tab turns into a space.
  77. X#    Using "cat $prefix.01 | ..." in case there are pipes embedded in
  78. X#    the command.
  79. X/bin/csh -f <<eof |& cat
  80. cat $prefix.01 | `cat $prefix.00`
  81. eof
  82. X
  83. X# Clean up temp files.
  84. X#
  85. cleanup:
  86. X/bin/rm -f $prefix.00 $prefix.01
  87. END_OF_FILE
  88. if test 1232 -ne `wc -c <'runfilter'`; then
  89.     echo shar: \"'runfilter'\" unpacked with wrong size!
  90. fi
  91. chmod +x 'runfilter'
  92. # end of 'runfilter'
  93. fi
  94. echo shar: End of shell archive.
  95. exit 0
  96. -- 
  97.         - Liz Allen-Mitchell    elroy!grian!liz@csvax.caltech.edu
  98.                     ames!elroy!grian!liz
  99. "God is light; in him there is no darkness at all." -- 1 John 1:5b
  100.